/*
 * @Author: '浪川' '1214391613@qq.com'
 * @Date: 2025-07-14 14:15:22
 * @LastEditors: '浪川' '1214391613@qq.com'
 * @LastEditTime: 2025-07-21 14:31:49
 * @FilePath: \passiflora-edulis-sims\src\stores\global-grid-store.ts
 * @Description: 全局方框设置
 *
 * Copyright (c) 2025 by '1214391613@qq.com', All Rights Reserved.
 */
import { defineStore, acceptHMRUpdate } from 'pinia'
import type { IGrid } from 'src/interfaces/IBook'

import { useCanvasStore } from './canvas-store'
import { unit2px } from 'src/utils/LeaferUtil'
import type { IStrokePaint } from 'leafer-ui'
export const useGlobalGridStore = defineStore('GlobalGrid', {
  state: (): IGrid => ({
    shape: 'round',
    text: undefined,
    width: 0.5,
    height: 0.5,
    x_interval: 0,
    y_interval: 0.2,
    stroke: {
      type: 'solid',
      color: '#000000',
      style: {
        strokeWidth: 1,
      },
    },
    offet_x: 0,
    offet_y: 0,
  }),

  getters: {
    grid_style(state): IGrid {
      const canvas_store = useCanvasStore()
      const style = {
        shape: state.shape,
        text: state.text,
        width: unit2px(state.width, canvas_store.unit, canvas_store.ppi),
        height: unit2px(state.height, canvas_store.unit, canvas_store.ppi),
        x_interval: unit2px(
          state.x_interval,
          canvas_store.unit,
          canvas_store.ppi
        ),
        y_interval: unit2px(
          state.y_interval,
          canvas_store.unit,
          canvas_store.ppi
        ),
        stroke: state.stroke as IStrokePaint,
        offet_x: unit2px(this.offet_x, canvas_store.unit, canvas_store.ppi),
        offet_y: unit2px(this.offet_y, canvas_store.unit, canvas_store.ppi),
      }
      return style
    },
  },

  actions: {},
})

if (import.meta.hot) {
  import.meta.hot.accept(acceptHMRUpdate(useGlobalGridStore, import.meta.hot))
}
